<template>
  <div>
    <el-dialog
      title="停车记录查看"
      :visible.sync="dialogTableVisible"
      width="600px"
    >
      <el-form
        :model="ruleForm"
        status-icon
        label-width="120px"
        class="demo-ruleForm"
      >
        <el-form-item label="序号:" :label-width="formLabelWidth">
          {{ ruleForm.soltId }}
        </el-form-item>
        <el-form-item label="车牌号码:" :label-width="formLabelWidth">
          {{ ruleForm.carNum }}
        </el-form-item>
        <el-form-item label="车辆编号:" :label-width="formLabelWidth">
          {{ ruleForm.cartype }}
        </el-form-item>
        <el-form-item label="进入时间:" :label-width="formLabelWidth">
          {{ ruleForm.entryTime }}
        </el-form-item>
        <el-form-item label="离开时间:" :label-width="formLabelWidth">
          {{ ruleForm.leaveTime }}
        </el-form-item>
        <el-form-item label="停车类型:" :label-width="formLabelWidth">
          {{ ruleForm.parkingType }}
        </el-form-item>
        <el-form-item label="实付金额:" :label-width="formLabelWidth">
          {{ ruleForm.realPayMoney }}
        </el-form-item>
        <el-form-item label="状态:" :label-width="formLabelWidth">
          {{ ruleForm.staus }}
        </el-form-item>
      </el-form>
    </el-dialog>

    <template>
      <el-form
        :inline="true"
        class="demo-form-inline"
        style="text-align: left"
        :model="ruleForm"
      >
        <el-form-item label="设备类型：">
          <el-input
            v-model="ruleForm.soltId"
            placeholder="输入设备编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="设备型号：">
          <el-input
            v-model="ruleForm.carNum"
            placeholder="输入设备型号"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间：">
          <el-input
            v-model="ruleForm.unitType"
            placeholder="输入创建时间"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getsmartLamp">查询</el-button>
          <el-button type="info" @click="resetForm('ruleForm')">重置</el-button>
          <el-button type="danger" @click="deletedata">批量删除</el-button>
        </el-form-item>
      </el-form>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="soltId" label="序号" width="180">
        </el-table-column>
        <el-table-column prop="carNum" label="车牌号码" width="180">
        </el-table-column>
        <el-table-column prop="cartype" label="车辆编号" width="180">
        </el-table-column>
        <el-table-column prop="entryTime" label="进入时间" width="180">
        </el-table-column>
        <el-table-column prop="" label="进场照片" width="180">
          <span class="demonstration">{{ fit }}</span>
          <el-image
            style="width: 100px; height: 100px"
            :src="url"
            :fit="fit"
          ></el-image>
        </el-table-column>
        <el-table-column prop="leaveTime" label="离开时间" width="180">
        </el-table-column>
        <el-table-column prop="" label="离场照片" width="180">
          <span class="demonstration">{{ fit }}</span>
          <el-image
            style="width: 100px; height: 100px"
            :src="urltwo"
          ></el-image>
        </el-table-column>
        <el-table-column prop="parkingType" label="停车类型" width="180">
          {{ "临时停车" }}
        </el-table-column>
        <!-- <el-table-column label="停车时长" width="180">
                  <template slot-scope="scope">
          {{ scope.row.leaveTime - scope.row.entryTime }}
        </template>
        </el-table-column> -->
        <el-table-column prop="realPayMoney" label="实付金额" width="180">
        </el-table-column>
        <el-table-column prop="staus" label="状态" width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.staus == true" style="color: green"
              >正常</span
            >
            <span v-if="scope.row.staus == false" style="color: red">异常</span>
          </template>
        </el-table-column>
        <el-table-column prop="" label="操作" width="180">
          <template slot-scope="scope">
            <el-link type="primary" @click="showdata(scope.row)">查看</el-link>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>
  
<script>
import {
  getParkingRecordData,
  deleteParkingRecordDatas,
} from "@/api/iotInfo/ParkingRecord";

export default {
  data() {
    return {
      formLabelWidth: "80px",
      dialogTableVisible: false,
      dialogVisible: false,
      fits: ["fill"],
      url: "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
      urltwo:
        "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
      ruleForm: {},
      //显示的数据
      tableData: [],
      multipleSelection: [],
      form: {},
      ids: [],
      ruleForm: {
        carNum: "",
        cartype: "",
        entryTime: "",
        leaveTime: "",
        parkingType: "",
        realPayMoney: "",
        staus: "",
      },
    };
  },

  created() {
    this.ListData();
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //显示方法
    ListData() {
      getParkingRecordData(this.form).then((res) => {
        this.tableData = res.data.data;
        //alert(this.tableData);
      });
    },
    //批量删除方法
    deletedata() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error("请选择一条数据");
        return;
      }
      this.multipleSelection.forEach((res) => {
        this.ids.push(res.id);
      });
      deleteParkingRecordDatas(this.ids).then((res) => {
        if (res.data) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.Show();
        } else {
          this.$message({
            message: "删除失败",
            type: "error",
          });
          return;
        }
      });
    },
    //表格显示具体时间
    formatDate(row, column) {
      // 获取单元格数据
      let data = row[column.property];
      if (data == null) {
        return 1;
      }
      let dt = new Date(data);
      return (
        dt.getFullYear() +
        "-" +
        (dt.getMonth() + 1) +
        "-" +
        dt.getDate() +
        " " +
        dt.getHours() +
        ":" +
        dt.getMinutes() +
        ":" +
        dt.getSeconds()
      );
    },
    //重置方法
    //   resetForm(formName) {
    //     this.$refs[formName].resetFields();
    //   }
    showdata(row) {
      this.dialogTableVisible = true;
      this.ruleForm = row;
    },
  },
};
</script>
  